package com.example.PolimiAssistant;

import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
import com.example.PolimiAssistant.common.AlertMessage;
import com.example.PolimiAssistant.common.CommonActivity;

import java.util.Locale;

/**
 * Created by Vlado on 22.06.2014.
 */
public class Classroom_detail extends CommonActivity {
    String latitude = "";
    String longitude = "";
    String name = "";
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.classroom_detail);

        TextView classroom_name = (TextView) findViewById(R.id.classroom_name);
        TextView class_building_name = (TextView) findViewById(R.id.class_building_name);
        TextView class_floor_name = (TextView) findViewById(R.id.class_floor_name);
        TextView class_seats_num = (TextView) findViewById(R.id.class_seats_num);
        TextView class_description = (TextView) findViewById(R.id.class_description);

        Intent i = getIntent();


        class_building_name.setText(i.getStringExtra("building"));
        class_floor_name.setText(i.getStringExtra("floor"));
        classroom_name.setText(i.getStringExtra("name"));
        class_description.setText(i.getStringExtra("description"));
        class_seats_num.setText(i.getStringExtra("num_of_seats"));
        latitude = i.getStringExtra("latitude");
        longitude = i.getStringExtra("longitude");
        name = i.getStringExtra("name");
    }

    public void ShowLocation(View view){
        String uri = String.format(Locale.ENGLISH, "http://maps.google.com/maps?&daddr=%s,%s (%s)", latitude, longitude, name);
        Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
        intent.setClassName("com.google.android.apps.maps", "com.google.android.maps.MapsActivity");
        try
        {
            startActivity(intent);
        }
        catch(Exception ex)
        {
            try
            {
                Intent unrestrictedIntent = new Intent(Intent.ACTION_VIEW, Uri.parse(uri));
                startActivity(unrestrictedIntent);
            }
            catch(Exception innerEx)
            {
                AlertMessage alert = new AlertMessage(context,"Please install a maps application");
                alert.Show();
            }
        }
    }
}